import { MigrationInterface, QueryRunner } from 'typeorm';

export class AddFileTypeAndFrequencyToMatchImportConfig1734567890000 implements MigrationInterface {
  name = 'AddFileTypeAndFrequencyToMatchImportConfig1734567890000';

  public async up(queryRunner: QueryRunner): Promise<void> {
    // 添加新字段
    await queryRunner.query(`
      ALTER TABLE \`match_import_config\` 
      ADD COLUMN \`fileType\` enum('homepage', 'score') NOT NULL DEFAULT 'homepage'
    `);
    
    await queryRunner.query(`
      ALTER TABLE \`match_import_config\` 
      ADD COLUMN \`frequency\` enum('daily', 'interval') NOT NULL DEFAULT 'daily'
    `);
    
    await queryRunner.query(`
      ALTER TABLE \`match_import_config\` 
      ADD COLUMN \`intervalMinutes\` int NULL
    `);
    
    await queryRunner.query(`
      ALTER TABLE \`match_import_config\` 
      ADD COLUMN \`maxRetries\` int NOT NULL DEFAULT 6
    `);
    
    await queryRunner.query(`
      ALTER TABLE \`match_import_config\` 
      ADD COLUMN \`retryIntervalMinutes\` int NOT NULL DEFAULT 5
    `);
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    // 删除新添加的字段
    await queryRunner.query(`
      ALTER TABLE \`match_import_config\` 
      DROP COLUMN \`retryIntervalMinutes\`
    `);
    
    await queryRunner.query(`
      ALTER TABLE \`match_import_config\` 
      DROP COLUMN \`maxRetries\`
    `);
    
    await queryRunner.query(`
      ALTER TABLE \`match_import_config\` 
      DROP COLUMN \`intervalMinutes\`
    `);
    
    await queryRunner.query(`
      ALTER TABLE \`match_import_config\` 
      DROP COLUMN \`frequency\`
    `);
    
    await queryRunner.query(`
      ALTER TABLE \`match_import_config\` 
      DROP COLUMN \`fileType\`
    `);
  }
}